package com.acme;

import java.io.Serializable;
import java.util.Date;

@SuppressWarnings("serial")
public class Bank implements Serializable {

	private final Client[] clients = new Client[10];
	private int maxClients = 0;
	private ClientRegistrationListener[] listeners = new ClientRegistrationListener[10];
	private int maxClientListeners = 0;

	public Bank() {

		class PrintListener implements ClientRegistrationListener {
			public void onClientAdded(Client client) {
				System.out.println(client.getSalutation() + " is added");
			}
		}
		class EmailNotificationListener implements ClientRegistrationListener {
			public void onClientAdded(Client client) {
				System.out.println("Notification email for client "
						+ client.getName() + " to be sent ");
			}
		}

		class DebugListener implements ClientRegistrationListener {
			public void onClientAdded(Client client) {
				System.out.println(client.getSalutation() + " :  " + new Date());
			}
		}

		listeners[0] = new PrintListener();
		listeners[1] = new EmailNotificationListener();
		listeners[2] = new DebugListener();
	}

	public Client addClient(final Client client) {
		clients[maxClients++] = client;

		for (ClientRegistrationListener listener : listeners) {
			if (listener != null) {
				listener.onClientAdded(client);
			} else {
				break;
			}
		}
		return client;
	}

	public void addClientListener(
			final ClientRegistrationListener clientListener) {
		listeners[maxClientListeners++] = clientListener;
	}

	public static void main(String[] args) {

		Client cl = new Client("Jons", Gender.MALE);
		cl.addAccount(new Account());
		
		new Bank().addClient(cl);
		
		Client c2 = new Client("Mary", Gender.FEMALE);
		c2.addAccount(new Account());
		
		new Bank().addClient(c2);
	}
}
